﻿// JScript 文件
function StyleTable (RID, ClsID, StName, StType)
{
    this.RID = RID;
    this.ClsID = ClsID;
    this.StName = StName;
    this.StType = StType;
};
function StyleTableCls (RID, AppWayIndex, ClsName)
{
    this.RID = RID;
    this.AppWayIndex = AppWayIndex;
    this.ClsName = ClsName;
};
function ReqCls (RID, StID, Indexes, ClsName)
{
    this.RID = RID;
    this.StID = StID;
    this.Indexes = Indexes;
    this.ClsName = ClsName;
};
function Req (RID, ClsID, ReqType, ReqTitle, Indexes, ReqOpt, TotalScore)
{
    this.RID = RID;
    this.ClsID = ClsID;
    this.ReqType = ReqType;
    this.ReqTitle = ReqTitle;
    this.Indexes = Indexes;
    this.ReqOpt = ReqOpt;
    this.TotalScore = TotalScore;
};
function Opt (index, title, score)
{
    this.index = index;
    this.title = title;
    this.score = score;
}

//获取元素的纵坐标
function getTop(e){
    var offset=e.offsetTop;
    if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
    return offset;
}
//获取元素的横坐标
function getLeft(e){
    var offset=e.offsetLeft;
    if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
    return offset;
}

function getCoord(obj, offsetLeft, offsetTop){
    var orig = obj;
    var left = 0;
    var top = 0;
    if(offsetLeft) left = offsetLeft;
    if(offsetTop) top = offsetTop;
    
    setTimeout(obj, 5);
    
    if(orig.offsetParent){
        left += obj.offsetLeft;
        top += obj.offsetTop;
        while (obj = obj.offsetParent) {
            left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
            top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
        }
    }
    return {left:left, top:top,
            width:orig.offsetWidth, height:orig.offsetHeight};
}

//function getCoord(objId){
//    //alert(objId);
//    var obj = document.getElementById(objId);
//    var orig = obj;
//    var left = 0;
//    var top = 0;
//    
//    setTimeout(obj, 5);
//    
//    if(orig.offsetParent){
//        left += obj.offsetLeft;
//        top += obj.offsetTop;
//        while (obj = obj.offsetParent) {
//            left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
//            top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
//        }
//    }
//    return {left:left, top:top,
//            width:orig.offsetWidth, height:orig.offsetHeight};
//}  

//  菜单类
function Menu(menuName, menuListName){
    this.menuName = menuName;
    this.menuListName = menuListName;
    this.objMenu = document.getElementById(this.menuName);
    this.objMenuList = document.getElementById(this.menuListName);
	this.objFocus = true;
	
	this.Show = function(){
		var hight = this.objMenu.offsetHeight;
		if(this.objMenu == null)
		    this.objMenu = document.getElementById(this.menuName);
		var rect = getCoord(this.objMenu);
		
		this.objMenuList.style.top = rect.top + hight;
		this.objMenuList.style.left = rect.left;
//			this.objMenuList.style.top = getTop(this.objMenu) + hight - document.body.scrollTop;
//			this.objMenuList.style.left = getLeft(this.objMenu);
		
		this.objMenuList.style.display = "block";
		this.objFocus = true;
	}
	
	this.Hide = function(){
		this.objMenuList.style.display = "none";
	}
//		this.objMenu.onblur = function (){
//			Menu.objFocus = false;
//			this.style.display = "none";
//		}
//		this.objMenuList.onblur = function (){
//			Menu.objListFocus = false;
//			if(!Menu.objFocus)
//				this.style.display = "none";
//		}
}
	
//  菜单管理类
function MenuManager(){
    MenuManager.menus = new Array();
	MenuManager.activeMenu = null;  // 当前激活的菜单
		// 添加菜单
		MenuManager.prototype.AddMenu = function(menuName, menuListName){
		    for(var i = 0; i < MenuManager.menus.length; i++ ) {
		        if(MenuManager.menus[i].menuName == menuName)
		            return;
		    }
			MenuManager.menus.push(new Menu(menuName, menuListName));
		}
		
		// 显示菜单
		MenuManager.prototype.ShowMenu = function(menuName){
			for (var i = 0; i < MenuManager.menus.length; i++) {
				//alert(MenuManager.menus[i].menuName);
				if (MenuManager.menus[i].menuName == menuName) {
					MenuManager.menus[i].Show();
					MenuManager.activeMenu = MenuManager.menus[i];
				}
				else {
					MenuManager.menus[i].Hide();
				}
			}
		}
		
		// 隐藏菜单
		MenuManager.prototype.HideMenu = function(menuName){
			for (var i = 0; i < MenuManager.menus.length; i++) {
				if (MenuManager.menus[i].menuName == menuName) {
					MenuManager.menus[i].Hide();
					break;
				}
			}
		}
		
        // 初始化菜单
        MenuManager.prototype.InitMenu = function(menuPopEvent){

//	                switch (menuPopEvent) {
//	                    case "click":
//	                        for (var i = 0; i < MenuManager.menus.length; i++) {
//								var index = i;
//	                        	MenuManager.menus[index].objMenu.onclick = function(){
//									MenuManager.menus[index].Show();
//									//MenuManager.ShowMenu(MenuManager.menus[index].menuName);
//								}
//	                        }
//	                        break;
//	                    case "mouseover":
//	                        for (var i = 0; i < MenuManager.menus.length; i++) {
//								var index = i;
//	                        	MenuManager.menus[index].objMenu.onmouseover = function(){
//									MenuManager.ShowMenu(MenuManager.menus[index].menuName);
//								}
//	                        }
//	                        break;
//	                    default:
//	                        break;
//	                }
        }  

};